package com.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.EmployeeBean;
import com.project.mapper.IDeptMapper;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private IEmployeeMapper ieMapper;
    @Autowired
    private IDeptMapper idMapper;

    @Override
    public void add(EmployeeBean employeeBean) {
        ieMapper.insert(employeeBean);
    }

    @Override
    public IPage<EmployeeBean> findByItem(Integer pageNo, String deptName, String name) {
        return ieMapper.findByItem(new Page(pageNo, 2), deptName, name);
    }

    @Override
    public EmployeeBean findById(Integer id) {
        EmployeeBean em = ieMapper.selectById(id);
        em.setDept(idMapper.selectById(em.getDeptId()));
        return em;
    }
}
